﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;

namespace NBA_Feed
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
        }

        private void HyperlinkButton_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            if (sender is HyperlinkButton)
            {
                HyperlinkButton btn = sender as HyperlinkButton;
                App.Url = btn.Tag.ToString();
                App.Title = btn.Content.ToString();
                this.NavigationService.Navigate(new Uri("/View/FeedListPage.xaml", UriKind.Relative));
            }
            e.Complete();
            e.Handled = true;
        }
    }
}